from skorch.core import *
import cv2
from skimage import measure
from skimage import filters
import csv


def mutil_image_std(path):
    img = np.load(path)
    img = img.astype(np.float32)
    img = img / 255
    return img.mean(), img.std()


def image_datasets_std(data_ids, njob=8):
    pool = Pool(njob)
    mean_std_lists = pool.map(mutil_image_std, data_ids)
    pool.close()
    pool.join()

    mean_std = np.array(mean_std_lists)

    return mean_std[:, 0].mean(),  mean_std[:, 1].mean(),


def stats_mean_std():
    root = Path("/home/blake/data/medical/datasets/vertebral/complete_vertebra/")
    images_path = root.joinpath('image')

    in_file_names = sorted(images_path.glob('*.npy'))

    mean, std = image_datasets_std(in_file_names)
    print(mean, std)


stats_mean_std()